var vm = avalon.define({
	$id: "addInfoVM",
	teacherDepartmentData: [],
	studentDepartmentData: []
	
});
window.onload=function() {
	$.ajax({
		url: "../FacultyStaffServlet?action=teacher",
		type:'post',
		success: function(tableData) {
			data=eval("("+tableData+")");
			vm.teacherDepartmentData=data.teacherPartment.concat();
			
        },

	}); 
	$.ajax({
		url: "../FacultyStaffServlet?action=student",
		type:'post',
		success: function(tableData) {
			data=eval("("+tableData+")");
			vm.studentDepartmentData=data.teacherPartment.concat();
			
        },

	}); 
}

$(function(){
	var canSubmit = true;
	$(".btn").mouseover(function(){
			$(this).css({
				backgroundColor: "#d7d5da",
		    	boxShadow: "rgb(107, 103, 103) 0px 0px 10px 5px",
		    	outline:"none"
			});
		});
	$(".btn").mouseout(function(){
			$(this).css({
				backgroundColor: "rgba(243, 243, 240, 0.49)",
		    	boxShadow: "0px 0px 5px 2px #afa7a7"
			});
		});
	$(".choose1").mousedown(function(e){
		if($(".choose1").children("option").length>5){
			$(".choose1").attr("size",4);
			$(".choose1").css("height","240px");
			$(".choose1 option").css("margin-left","4%");
		}
	});
	$(".choose1 option:first").attr("selected",true).siblings("option").removeAttr("selected");
	$(".choose1").blur(function(){
		$(".choose1").css("height","40px");
		$(".choose1").attr("size",0);
	});
	$(".choose1").change(function(){
		$(".choose1").css("height","40px");
		$(".choose1").attr("size",0);
	});
	$(".choose1 option").click(function(){
		$(this).attr("selected",true).siblings("option").removeAttr("selected");
		$(".choose1").attr("size",0);
			$(".choose1").css("height","40px");
	});
})
$().ready(function() {
// 在键盘按下并释放及提交后验证提交表单
  $("#signupForm").validate({
	    rules: {
	    	photo: {
	    		required:true,
	    		url:true
	    	},
	    	username: "required",
	    	jobNumber:"required",
	    	department:"required",
	    	IDNumber:"required"
	      
	    },
	   
	});
})
	function sub(){
		var file=$("#file").val();
		if(file==""||file==null){
			alert("请选择照片");
			return;
		}else{
			$("#submit").attr("type","submit");
			$("#submit").submit();
		}
	}
	
	function selectfile(){
		$("#file").click();
	} 

	//将上传图片添加到头像框中
	$(function(){
		var file=document.getElementById("file");
		
		if(typeof FileReader==='undefined'){ 
		     //result.innerHTML = "抱歉，你的浏览器不支持 FileReader"; 
			file.setAttribute('disabled','disabled'); 
		}else{ 
			file.addEventListener('change',readFile,false); 
		     /*input1.addEventListener('change',function (e){
		     	console.log(this.files);//上传的文件列表
		     },false); */
		}
		function readFile(){ 
			var file = this.files[0];//获取上传文件列表中第一个文件
			if(!/image\/\w+/.test(file.type)){
			//图片文件的type值为image/png或image/jpg
				alert("文件必须为图片！");
				return false; 
			} 
			
			var reader = new FileReader();//实例一个文件对象
			reader.readAsDataURL(file);//把上传的文件转换成url
			//当文件读取成功便可以调取上传的接口
			reader.onload = function(e){ 
				 $("#img").attr("src",e.target.result);
				 
			}
		};
	})
	
	
